import request from '@/utils/request'
import qs from 'qs'
import { baseUrl } from '@/config/env';


//获取短信验证码
export function getMsgCode(phone){
  return request({
    url:baseUrl+'/rest/common/smsCode',
    params:{
      phone
    }
  })
}

//用户注册
export function register(data){
  return request({
    url: baseUrl+'/rest/common/reg',
    method: 'post',
    meta: {
      isToken: false
    },
    data:data
  })
}

//用户名密码登录
export function loginByUsername(data) {
  return request({
    url: baseUrl+'/login',
    method: 'post',
    meta: {
      isSerialize: false,
      isToken: false
    },
    data: qs.stringify(data)
  })
}

//手机号码登录
export function loginByPhone(data) {
  return request({
    url: baseUrl+'/rest/common/app/login',
    method: 'post',
    meta: {
      isSerialize: false,
      isToken: false
    },
    data: data
  })
}

//获取用户信息
export function getUserInfo() {
  return request({
    url: baseUrl+'/rest/getUserInfo',
    method: 'post'
  })
}

//app接口  修改用户信息用于个人中心使用
export function editInfo(data) {
  return request({
    url: baseUrl+'/rest/member/info/edit',
    method: 'post',
    meta: {
      isSerialize: false,
    },
    data: data
  })
}

//app接口  获取用户信息用于个人中心使用
export function getInfo() {
  return request({
    url: baseUrl+'/rest/member/info/detail',
    method: 'get'
  })
}

//获取用户头像
export function previewAvatar(fileId) {
  return request({
    url: `${baseUrl}/rest/common/preview${fileId}`,
    method: 'get'
  })
}

//用户登出
export function logout() {
  return request({
    url: baseUrl+'/logout',
    meta: {
      isToken: false
    },
    method: 'get'
  })
}

//获取系统菜单
export function getMenu(){
  return request({
    url: baseUrl+'/rest/menus',
    method: 'post'
  })
}

//修改用户头像
export function alterAvatar(fileId){
  return request({
    url: baseUrl+'/rest/system/updateAvatar',
    headers:{"Content-Type":"application/x-www-form-urlencoded"},
    method: 'post',
    meta: {
      isSerialize: false,
    },
    data:qs.stringify({
      fileId:fileId
    })
  })
}


//修改密码
export function alterPass(oldPassword,newPassword){
  return request({
    url: baseUrl+'/rest/mgr/changePwd',
    headers:{"Content-Type":"application/x-www-form-urlencoded"},
    method: 'post',
    meta: {
      isSerialize: false,
    },
    data:qs.stringify({
      oldPassword:oldPassword,
      newPassword:newPassword
    })
  })
}
